home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 2
/
Gold Medal Software Volume 2 (Gold Medal) (1994).iso
/
windows
/
win31
/
macsyma.arj
/
MACSDEMO.EXE
/
GENERAL.OUT
< prev
next >
Wrap
Text File
|
1993-09-15
|
64KB
|
1,232 lines
(c1) /* GENERAL INTRODUCTORY DEMONSTRATION OF MACSYMA
We recommend that you do `RESET(ALL)$' and `KILL(ALL)$' before running this demo.
When the prompt `_' appears, push the ENTER key to continue. */
(loadprint:false, pause_prompt:"_")$
(c2) (clearscreen(),
disp(dpart(" WELCOME TO MACSYMA ")),disp(" "),
disp(" POWER OF SYMBOLIC MATH SOFTWARE "),
disp(" ALGEBRA "),
disp(" CALCULUS "),
disp(" SYMBOLIC APPROXIMATION METHODS "),
disp(" NUMERICAL ANALYSIS "),
disp(" GRAPHICS ") )$
|$label(0,15,Times New Roman,)$box( WELCOME TO MACSYMA )
|$label(0,15,Times New Roman,)
|$label(0,15,Times New Roman,) POWER OF SYMBOLIC MATH SOFTWARE
|$label(0,15,Times New Roman,) ALGEBRA
|$label(0,15,Times New Roman,) CALCULUS
|$label(0,15,Times New Roman,) SYMBOLIC APPROXIMATION METHODS
|$label(0,15,Times New Roman,) NUMERICAL ANALYSIS
|$label(0,15,Times New Roman,) GRAPHICS
(c3) (clearscreen(),
disp(dpart(" ALGEBRA ")),
disp(" Simultaneous Algebraic Equations "),
disp(" Matrix Computations "),
disp(" Simplification of Expressions "),
disp(" Trigonometry "),
disp(" Pattern Matching "),
disp(" Sums of Series "))$
|$label(0,15,Times New Roman,)$box( ALGEBRA )
|$label(0,15,Times New Roman,) Simultaneous Algebraic Equations
|$label(0,15,Times New Roman,) Matrix Computations
|$label(0,15,Times New Roman,) Simplification of Expressions
|$label(0,15,Times New Roman,) Trigonometry
|$label(0,15,Times New Roman,) Pattern Matching
|$label(0,15,Times New Roman,) Sums of Series
(c4) (clearscreen(),
disp(dpart(" ALGEBRA . . . Simultaneous Algebraic Equations ")),
disp(" Example: Solve three linear equations for X, Y, Z "))$
|$label(0,15,Times New Roman,)$box( ALGEBRA . . . Simultaneous Algebraic Equations )
|$label(0,15,Times New Roman,) Example: Solve three linear equations for X$, Y$, Z
(c5) eq1: 3*x+5*y+d*z=13*a;
|$label(0,15,Times New Roman,$(d5$))d$in( )z$hinge()$in( + )5$in( )y$hinge()$in( + )3$in( )x$hinge()$in( = )13$hinge()$in( )a
(c6) eq2: 19*x+e*y+29*z=37*b;
|$label(0,15,Times New Roman,$(d6$))29$in( )z$hinge()$in( + )e$in( )y$hinge()$in( + )19$in( )x$hinge()$in( = )37$hinge()$in( )b
(c7) eq3: 43*x+47*y+f*z=61*c;
|$label(0,15,Times New Roman,$(d7$))f$in( )z$hinge()$in( + )47$in( )y$hinge()$in( + )43$in( )x$hinge()$in( = )61$hinge()$in( )c
(c8) solve([eq1,eq2,eq3],[x,y,z]);
|$label(0,15,Times New Roman,$(d8$))$open([)$open([)x$hinge()$in( = )$q(a$in( )$paren(17719$in( - )13$in( )e$in( )f,$(,$))$in( + )185$in( )b$in( )f$in( + )d$in( )$paren(61$in( )c$in( )e$in( - )1739$in( )b,$(,$))$in( - )8845$in( )c,$in( - )3$in( )e$in( )f$in( + )95$in( )f$in( + )d$in( )$paren(43$in( )e$in( - )893,$(,$))$in( - )2146)$ina($, )$hinge()y$hinge()$in( = )$q(a$in( )$paren(247$in( )f$in( - )16211,$(,$))$in( - )111$in( )b$in( )f$in( + )$paren(1591$in( )b$in( - )1159$in( )c,$(,$))$in( )d$in( + )5307$in( )c,$in( - )3$in( )e$in( )f$in( + )95$in( )f$in( + )d$in( )$paren(43$in( )e$in( - )893,$(,$))$in( - )2146)$ina($, )$hinge()z$hinge()$in( = )$q(a$in( )$paren(559$in( )e$in( - )11609,$(,$))$in( - )183$in( )c$in( )e$in( + )5795$in( )c$in( - )2738$in( )b,$in( - )3$in( )e$in( )f$in( + )95$in( )f$in( + )d$in( )$paren(43$in( )e$in( - )893,$(,$))$in( - )2146)$close(])$close(])
(c9) (clearscreen(),
disp(" ALGEBRA . . . Simultaneous Algebraic Equations, continued "),
disp(" Example: Solve three non-linear equations for X, Y, Z "))$
|$label(0,15,Times New Roman,) ALGEBRA . . . Simultaneous Algebraic Equations$, continued
|$label(0,15,Times New Roman,) Example: Solve three non-linear equations for X$, Y$, Z
(c10) eq1: a*x*y*z = 42;
|$label(0,15,Times New Roman,$(d10$))a$hinge()$in( )x$hinge()$in( )y$hinge()$in( )z$hinge()$in( = )42
(c11) eq2: -z+y+x = -2;
|$label(0,15,Times New Roman,$(d11$))$in( - )z$hinge()$in( + )y$hinge()$in( + )x$hinge()$in( = )$in( - )2
(c12) eq3: -3*z+2*y+3*x = -9;
|$label(0,15,Times New Roman,$(d12$))$in( - )3$in( )z$hinge()$in( + )2$in( )y$hinge()$in( + )3$in( )x$hinge()$in( = )$in( - )9
(c13) solve([eq1,eq2,eq3],[x,y,z]);
|$label(0,15,Times New Roman,$(d13$))$open([)$open([)x$hinge()$in( = )$q($sqrt(25$in( )$sup(a,2)$in( + )56$in( )a)$in( - )5$in( )a,2$in( )a)$ina($, )$hinge()y$hinge()$in( = )3$ina($, )$hinge()z$hinge()$in( = )$q($sqrt(25$in( )a$in( + )56)$in( + )5$in( )$sqrt(a),2$in( )$sqrt(a))$close(])$ina($, )$hinge()$open([)x$hinge()$in( = )$in( - )$q($sqrt(25$in( )$sup(a,2)$in( + )56$in( )a)$in( + )5$in( )a,2$in( )a)$ina($, )$hinge()y$hinge()$in( = )3$ina($, )$hinge()z$hinge()$in( = )$in( - )$q($sqrt(25$in( )a$in( + )56)$in( - )5$in( )$sqrt(a),2$in( )$sqrt(a))$close(])$close(])
(c14) (remvalue(eq1,eq2,eq3),
clearscreen(),
disp(dpart(" ALGEBRA . . . Matrix Computations ")),
disp(" Example: Find the determinant of a matrix ") )$
|$label(0,15,Times New Roman,)$box( ALGEBRA . . . Matrix Computations )
|$label(0,15,Times New Roman,) Example: Find the determinant of a matrix
(c15) mat1:matrix([1,a,a^2],[1,b,b^2],[1,c,c^2]);
|$label(0,15,Times New Roman,$(d15$))$matrix(3,3,1,a,$sup(a,2),1,b,$sup(b,2),1,c,$sup(c,2))
(c16) factor(determinant(mat1));
|$label(0,15,Times New Roman,$(d16$))$open($()b$hinge()$in( - )a$close($))$hinge()$in( )$open($()c$hinge()$in( - )a$close($))$hinge()$in( )$open($()c$hinge()$in( - )b$close($))
(c17) /* Example: Invert a matrix */
mat1^^-1,factor,detout;
|$label(0,15,Times New Roman,$(d17$))$q($matrix(3,3,b$in( )c$in( )$paren(c$in( - )b,$(,$)),$in( - )a$in( )c$in( )$paren(c$in( - )a,$(,$)),a$in( )b$in( )$paren(b$in( - )a,$(,$)),$sup(b,2)$in( - )$sup(c,2),$sup(c,2)$in( - )$sup(a,2),$sup(a,2)$in( - )$sup(b,2),c$in( - )b,a$in( - )c,b$in( - )a),$paren(b$in( - )a,$(,$))$in( )$paren(c$in( - )a,$(,$))$in( )$paren(c$in( - )b,$(,$)))
(c18) (remvalue(mat1),
clearscreen(),
disp(" ALGEBRA . . . Matrix Computations, continued "),
disp(" Example: Find eigenvalues and eigenvectors of a matrix ") )$
|$label(0,15,Times New Roman,) ALGEBRA . . . Matrix Computations$, continued
|$label(0,15,Times New Roman,) Example: Find eigenvalues and eigenvectors of a matrix
(c19) mat1:matrix([2,6],[6,a]);
|$label(0,15,Times New Roman,$(d19$))$matrix(2,2,2,6,6,a)
(c20) evec:eigenvectors(mat1);
|$label(0,15,Times New Roman,$(d20$))$open([)$open([)$open([)$in( - )$q($sqrt($sup(a,2)$in( - )4$in( )a$in( + )148)$in( - )a$in( - )2,2)$ina($, )$q($sqrt($sup(a,2)$in( - )4$in( )a$in( + )148)$in( + )a$in( + )2,2)$close(])$ina($, )$hinge()$open([)1$ina($, )1$close(])$close(])$ina($, )$hinge()$open([)1$ina($, )$hinge()$in( - )$q($sqrt($sup(a,2)$in( - )4$in( )a$in( + )148)$in( - )a$in( + )2,12)$close(])$ina($, )$hinge()$open([)1$ina($, )$hinge()$q($sqrt($sup(a,2)$in( - )4$in( )a$in( + )148)$in( + )a$in( - )2,12)$close(])$close(])
(c21) /* We can examine these results graphically.
*/
(l1:part(evec,1,1,1),l2:part(evec,1,1,2),
equalscale:false,ymin:-10,ymax:10,
plot([l1,l2],a,-50,50,[0,2],"Matrix Parameter `A'",Eigenvalue,
"Two Eigenvalues as Functions of the Matrix Parameter `A'") )$
(c22) (remvalue(evec,l1,l2,mat1,ymax,ymin),reset(equalscale),
clearscreen(),
disp(dpart(" ALGEBRA . . . Simplification of Expressions ")),
disp(" Example: Expand and factor a multivariate polynomial ") )$
|$label(0,15,Times New Roman,)$box( ALGEBRA . . . Simplification of Expressions )
|$label(0,15,Times New Roman,) Example: Expand and factor a multivariate polynomial
(c23) expr:(y^3-x^2)^3*(x+y+z)^2;
|$label(0,15,Times New Roman,$(d23$))$sup($paren($sup(y,3)$in( - )$sup(x,2),$(,$)),3)$hinge()$in( )$sup($paren(z$in( + )y$in( + )x,$(,$)),2)
(c24) expr:expand(expr);
|$label(0,15,Times New Roman,$(d24$))$sup(y,9)$in( )$sup(z,2)$hinge()$in( - )3$in( )$sup(x,2)$in( )$sup(y,6)$in( )$sup(z,2)$hinge()$in( + )3$in( )$sup(x,4)$in( )$sup(y,3)$in( )$sup(z,2)$hinge()$in( - )$sup(x,6)$in( )$sup(z,2)$hinge()$in( + )2$in( )$sup(y,10)$in( )z$hinge()$in( + )2$in( )x$in( )$sup(y,9)$in( )z$hinge()$in( - )6$in( )$sup(x,2)$in( )$sup(y,7)$in( )z$hinge()$in( - )6$in( )$sup(x,3)$in( )$sup(y,6)$in( )z$hinge()$in( + )6$in( )$sup(x,4)$in( )$sup(y,4)$in( )z$hinge()$in( + )6$in( )$sup(x,5)$in( )$sup(y,3)$in( )z$hinge()$in( - )2$in( )$sup(x,6)$in( )y$in( )z$hinge()$in( - )2$in( )$sup(x,7)$in( )z$hinge()$in( + )$sup(y,11)$hinge()$in( + )2$in( )x$in( )$sup(y,10)$hinge()$in( + )$sup(x,2)$in( )$sup(y,9)$hinge()$in( - )3$in( )$sup(x,2)$in( )$sup(y,8)$hinge()$in( - )6$in( )$sup(x,3)$in( )$sup(y,7)$hinge()$in( - )3$in( )$sup(x,4)$in( )$sup(y,6)$hinge()$in( + )3$in( )$sup(x,4)$in( )$sup(y,5)$hinge()$in( + )6$in( )$sup(x,5)$in( )$sup(y,4)$hinge()$in( + )3$in( )$sup(x,6)$in( )$sup(y,3)$hinge()$in( - )$sup(x,6)$in( )$sup(y,2)$hinge()$in( - )2$in( )$sup(x,7)$in( )y$hinge()$in( - )$sup(x,8)
(c25) factor(expr);
|$label(0,15,Times New Roman,$(d25$))$sup($paren($sup(y,3)$in( - )$sup(x,2),$(,$)),3)$hinge()$in( )$sup($paren(z$in( + )y$in( + )x,$(,$)),2)
(c26) (clearscreen(),
disp(" ALGEBRA . . . Simplification of Expressions, continued "),
disp(" Example: Simplify a rational expression ") )$
|$label(0,15,Times New Roman,) ALGEBRA . . . Simplification of Expressions$, continued
|$label(0,15,Times New Roman,) Example: Simplify a rational expression
(c27) expr:(sqrt(r^2+a^2)+a)*(sqrt(r^2+b^2)+b)/r^2
-(sqrt(r^2+b^2)+sqrt(r^2+a^2)+b+a)/(sqrt(r^2+b^2)+sqrt(r^2+a^2)-b-a);
|$label(0,15,Times New Roman,$(d27$))$q($paren($sqrt($sup(r,2)$in( + )$sup(a,2))$in( + )a,$(,$))$in( )$paren($sqrt($sup(r,2)$in( + )$sup(b,2))$in( + )b,$(,$)),$sup(r,2))$hinge()$in( - )$q($sqrt($sup(r,2)$in( + )$sup(b,2))$in( + )$sqrt($sup(r,2)$in( + )$sup(a,2))$in( + )b$in( + )a,$sqrt($sup(r,2)$in( + )$sup(b,2))$in( + )$sqrt($sup(r,2)$in( + )$sup(a,2))$in( - )b$in( - )a)
(c28) ratsimp(expr);
|$label(0,15,Times New Roman,$(d28$))0
(c29) (clearscreen(),
disp(" ALGEBRA . . . Simplification of Expressions, continued "),
disp(" Example: Simplifying an expression subject to constraints "))$
|$label(0,15,Times New Roman,) ALGEBRA . . . Simplification of Expressions$, continued
|$label(0,15,Times New Roman,) Example: Simplifying an expression subject to constraints
(c30) [constraint1:y^2+x^2 = m, constraint2:-c^3-b^3+a^3 = 3*n];
|$label(0,15,Times New Roman,$(d30$))$open([)$sup(y,2)$hinge()$in( + )$sup(x,2)$hinge()$in( = )m$ina($, )$hinge()$in( - )$sup(c,3)$hinge()$in( - )$sup(b,3)$hinge()$in( + )$sup(a,3)$hinge()$in( = )3$hinge()$in( )n$close(])
(c31) expr:expand((-c^3-b^3+a^3)^2*(y^2+x^2)^2);
|$label(0,15,Times New Roman,$(d31$))$sup(c,6)$in( )$sup(y,4)$hinge()$in( + )2$in( )$sup(b,3)$in( )$sup(c,3)$in( )$sup(y,4)$hinge()$in( - )2$in( )$sup(a,3)$in( )$sup(c,3)$in( )$sup(y,4)$hinge()$in( + )$sup(b,6)$in( )$sup(y,4)$hinge()$in( - )2$in( )$sup(a,3)$in( )$sup(b,3)$in( )$sup(y,4)$hinge()$in( + )$sup(a,6)$in( )$sup(y,4)$hinge()$in( + )2$in( )$sup(c,6)$in( )$sup(x,2)$in( )$sup(y,2)$hinge()$in( + )4$in( )$sup(b,3)$in( )$sup(c,3)$in( )$sup(x,2)$in( )$sup(y,2)$hinge()$in( - )4$in( )$sup(a,3)$in( )$sup(c,3)$in( )$sup(x,2)$in( )$sup(y,2)$hinge()$in( + )2$in( )$sup(b,6)$in( )$sup(x,2)$in( )$sup(y,2)$hinge()$in( - )4$in( )$sup(a,3)$in( )$sup(b,3)$in( )$sup(x,2)$in( )$sup(y,2)$hinge()$in( + )2$in( )$sup(a,6)$in( )$sup(x,2)$in( )$sup(y,2)$hinge()$in( + )$sup(c,6)$in( )$sup(x,4)$hinge()$in( + )2$in( )$sup(b,3)$in( )$sup(c,3)$in( )$sup(x,4)$hinge()$in( - )2$in( )$sup(a,3)$in( )$sup(c,3)$in( )$sup(x,4)$hinge()$in( + )$sup(b,6)$in( )$sup(x,4)$hinge()$in( - )2$in( )$sup(a,3)$in( )$sup(b,3)$in( )$sup(x,4)$hinge()$in( + )$sup(a,6)$in( )$sup(x,4)
(c32) scsimp(expr,constraint1,constraint2);
|$label(0,15,Times New Roman,$(d32$))9$hinge()$in( )$sup(m,2)$hinge()$in( )$sup(n,2)
(c33) (remvalue(constraint1,constraint2,expr),
clearscreen(),
disp(" ALGEBRA . . . Trigonometry "),
disp(" Example: Apply trigonometric identities "))$
|$label(0,15,Times New Roman,) ALGEBRA . . . Trigonometry
|$label(0,15,Times New Roman,) Example: Apply trigonometric identities
(c34) expr:sin(2*y+x);
|$label(0,15,Times New Roman,$(d34$))sin$paren(2$in( )y$in( + )x)
(c35) expr:trigexpand(expr);
|$label(0,15,Times New Roman,$(d35$))cos$paren(x)$in( )sin$paren(2$in( )y)$hinge()$in( + )sin$paren(x)$in( )cos$paren(2$in( )y)
(c36) expr:expand(trigexpand(expr));
|$label(0,15,Times New Roman,$(d36$))$in( - )sin$paren(x)$in( )$sup(sin,2)$paren(y)$hinge()$in( + )2$in( )cos$paren(x)$in( )cos$paren(y)$in( )sin$paren(y)$hinge()$in( + )sin$paren(x)$in( )$sup(cos,2)$paren(y)
(c37) /* Perform the inverse operation. */
expr:trigreduce(expr);
|$label(0,15,Times New Roman,$(d37$))sin$paren(2$in( )y$in( + )x)
(c38) /*
Example: Expand a more complex trigonometric expression.
*/
expr: - sin(y-x)*sin(z-x)*sin(z-y) - cos(y-x)*cos(z-x)*sin(z-y)
+ cos(y-x)*sin(z-x)*cos(z-y) - sin(y-x)*cos(z-x)*cos(z-y)$
(c39) expr:expand(trigexpand(expr));
|$label(0,15,Times New Roman,$(d39$))0
(c40) (remvalue(expr),
clearscreen(),
disp(dpart(" ALGEBRA . . . Pattern Matching ")),
disp(" Example: Bessel identity J[-N](X) = (-1)^N J[N](X) for integer N>0 ") )$
|$label(0,15,Times New Roman,)$box( ALGEBRA . . . Pattern Matching )
|$label(0,15,Times New Roman,) Example: Bessel identity J[-N]$(X$) = $(-1$)^N J[N]$(X$) for integer N>0
(c41) /* Macsyma starts out not knowing the identity. */ J[-3](X) ;
|$label(0,15,Times New Roman,$(d41$))$sub(j,- 3)$paren(x)
(c42) /* First, define a predicate testing for a positive integer. */
posintp(n):=is(integerp(n) and n>0)$
(c43) /* Define dummy variables for N and X for use in pattern matching. */
matchdeclare(n_match,posintp,x_match,true)$
(c44) /* Teach Macsyma the Bessel identity. */
tellsimp(j[-n_match](x_match),j[n_match](x_match)*(-1)^n_match)$
(c45) [j[-3](x),j[3](x)];
|$label(0,15,Times New Roman,$(d45$))$open([)$in( - )$sub(j,3)$paren(x)$ina($, )$hinge()$sub(j,3)$paren(x)$close(])
(c46) [j[-4](x),j[4](x)];
|$label(0,15,Times New Roman,$(d46$))$open([)$sub(j,4)$paren(x)$ina($, )$hinge()$sub(j,4)$paren(x)$close(])
(c47) (kill(j,n_match,x,x_match),remfunction(posintp),
clearscreen(),
if get('nusum,'version)=false then load('nusum),
disp(dpart(" ALGEBRA . . . Sums of Series ")),
disp(" Example: Find indefinite sum of a series in closed form. ") )$
|$label(0,15,Times New Roman,)$box( ALGEBRA . . . Sums of Series )
|$label(0,15,Times New Roman,) Example: Find indefinite sum of a series in closed form.
(c48) (expr:i/(4*i^2-1)^2,'sum(expr,i,0,n));
|$label(0,15,Times New Roman,$(d48$))$sum($q(i,$sup($paren(4$in( )$sup(i,2)$in( - )1,$(,$)),2)),i = 0,n)
(c49) nusum(expr,i,1,n);
|$label(0,15,Times New Roman,$(d49$))$q(n$in( )$paren(n$in( + )1,$(,$)),2$in( )$sup($paren(2$in( )n$in( + )1,$(,$)),2))
(c50) (remvalue(expr),
clearscreen(),
disp(dpart(" CALCULUS ")),
disp(" Derivatives and Limits "),
disp(" Indefinite and Definite Integrals "),
disp(" Laplace and Fourier Transforms "),
disp(" Ordinary Differential Equations "),
disp(" Integral Equations "),
disp(" Vector Analysis "),
disp(" Finite Difference Equations "),
disp(" Tensor Analysis ") )$
|$label(0,15,Times New Roman,)$box( CALCULUS )
|$label(0,15,Times New Roman,) Derivatives and Limits
|$label(0,15,Times New Roman,) Indefinite and Definite Integrals
|$label(0,15,Times New Roman,) Laplace and Fourier Transforms
|$label(0,15,Times New Roman,) Ordinary Differential Equations
|$label(0,15,Times New Roman,) Integral Equations
|$label(0,15,Times New Roman,) Vector Analysis
|$label(0,15,Times New Roman,) Finite Difference Equations
|$label(0,15,Times New Roman,) Tensor Analysis
(c51) (clearscreen(),
disp(dpart(" CALCULUS . . . Derivatives and Limits ")),
disp(" A classic textbook example of differentiation ") )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Derivatives and Limits )
|$label(0,15,Times New Roman,) A classic textbook example of differentiation
(c52) f(x):=x^x^x;
|$label(0,15,Times New Roman,$(d52$))f$paren(x)$hinge()$in( := )$sup(x,$sup(x,x))
(c53) diff(f(x),x);
|$label(0,15,Times New Roman,$(d53$))$sup(x,$sup(x,x))$hinge()$in( )$open($()$sup(x,x)$in( )log$paren(x)$in( )$paren(log$paren(x)$in( + )1,$(,$))$hinge()$in( + )$sup(x,x$in( - )1)$close($))
(c54) /*
Example: Differentiating a nested function */
f(x):=erf(tan(acos(log(x))));
|$label(0,15,Times New Roman,$(d54$))f$paren(x)$hinge()$in( := )erf$paren(tan$paren(acos$paren(log$paren(x))))
(c55) diff(f(x),x),ratsimp;
|$label(0,15,Times New Roman,$(d55$))$in( - )$q(2$in( )$sup($e(),1$in( - )$q(1,$sup(log,2)$paren(x))),$sqrt($greektext(p))$in( )x$in( )$sup(log,2)$paren(x)$in( )$sqrt(1$in( - )$sup(log,2)$paren(x)))
(c56) (clearscreen(),
disp(" CALCULUS . . . Derivatives and Limits, continued "),
disp(" Example: Direction-dependent limits ") )$
|$label(0,15,Times New Roman,) CALCULUS . . . Derivatives and Limits$, continued
|$label(0,15,Times New Roman,) Example: Direction-dependent limits
(c57) limit(tan(x),x,%pi/2,plus);
|$label(0,15,Times New Roman,$(d57$))$greektext(-) $greektext(Ñ)
(c58) limit(tan(x),x,%pi/2,minus);
|$label(0,15,Times New Roman,$(d58$))$greektext(Ñ)
(c59) limit(tan(x),x,%pi/2);
|$label(0,15,Times New Roman,$(d59$))infinity
(c60) /* Example: Limits at infinity */
f(x):= (1+1/x)^x;
|$label(0,15,Times New Roman,$(d60$))f$paren(x)$hinge()$in( := )$sup($paren(1$in( + )$q(1,x),$(,$)),x)
(c61) limit(f(x),x,inf);
|$label(0,15,Times New Roman,$(d61$))$e()
(c62) (remfunction(f),
clearscreen(),
disp(dpart(" CALCULUS . . . Indefinite and Definite Integrals ")),
disp(" Example: Evaluate an indefinite integral. ") )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Indefinite and Definite Integrals )
|$label(0,15,Times New Roman,) Example: Evaluate an indefinite integral.
(c63) f(x):=(log(x)-1)/(log(x)^2-x^2);
|$label(0,15,Times New Roman,$(d63$))f$paren(x)$hinge()$in( := )$q(log$paren(x)$in( - )1,$sup(log,2)$paren(x)$in( - )$sup(x,2))
(c64) integrate(f(x),x);
|$label(0,15,Times New Roman,$(d64$))$q(log$paren(log$paren(x)$in( + )x),2)$hinge()$in( - )$q(log$paren(log$paren(x)$in( - )x),2)
(c65) /* Verify that differentiation returns the original integrand. */
diff(%,x),ratsimp;
|$label(0,15,Times New Roman,$(d65$))$q(log$paren(x)$in( - )1,$sup(log,2)$paren(x)$in( - )$sup(x,2))
(c66) (clearscreen(),
disp(" CALCULUS . . . Indefinite and Definite Integrals, continued "),
disp(" Example: Evaluate some definite integrals. "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Indefinite and Definite Integrals$, continued
|$label(0,15,Times New Roman,) Example: Evaluate some definite integrals.
(c67) assume(a>0,b>0)$
(c68) 'integrate(sin(a*x)^2/(x^2),x,0,inf)=integrate(sin(a*x)^2/(x^2),x,0,inf);
|$label(0,15,Times New Roman,$(d68$))$integrate($q($sup(sin,2)$paren(a$in( )x),$sup(x,2)),x,0,$greektext(Ñ))$hinge()$in( = )$q($greektext(p)$in( )a,2)
(c69) /* Macsyma can use information about symbolic parameters. */
declare([a,b],even)$
(c70) 'integrate(cos(x)^a*sin(x)^b,x,0,2*%pi)=integrate(cos(x)^a*sin(x)^b,x,0,2*%pi);
|$label(0,15,Times New Roman,$(d70$))$integrate($sup(cos,a)$paren(x)$in( )$sup(sin,b)$paren(x),x,0,2$in( )$greektext(p))$hinge()$in( = )2$hinge()$in( )$greektext(B)$paren($q(a$in( + )1,2)$ina($, )$hinge()$q(b$in( + )1,2))
(c71) (forget(a>0,b>0),remove([a,b],even),
clearscreen(),
disp(dpart(" CALCULUS . . . Laplace and Fourier Transforms ")),
disp(" Example: Use Laplace transform to solve ordinary differential equation. ") )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Laplace and Fourier Transforms )
|$label(0,15,Times New Roman,) Example: Use Laplace transform to solve ordinary differential equation.
(c72) (derivabbrev:true, eq:diff(x(t),t)=-2*x(t)+cos(t)-1);
|$label(0,15,Times New Roman,$(d72$))$sub(x$paren(t),t)$hinge()$in( = )cos$paren(t)$hinge()$in( - )2$in( )x$paren(t)$hinge()$in( - )1
(c73) /* Initial condition: X(0)=1
Take the Laplace transform. */
(assume(s>0),lt_eq:laplace(eq,t,s));
|$label(0,15,Times New Roman,$(d73$))s$in( )laplace$paren(x$paren(t)$ina($, )$hinge()t$ina($, )$hinge()s)$hinge()$in( - )x$paren(0)$hinge()$in( = )$in( - )2$in( )laplace$paren(x$paren(t)$ina($, )$hinge()t$ina($, )$hinge()s)$hinge()$in( + )$q(s,$sup(s,2)$in( + )1)$hinge()$in( - )$q(1,s)
(c74) /* Solve for the Laplace transform of X. */
soln:solve(lt_eq,laplace(x(t),t,s));
|$label(0,15,Times New Roman,$(d74$))$open([)laplace$paren(x$paren(t)$ina($, )$hinge()t$ina($, )$hinge()s)$hinge()$in( = )$q(x$paren(0)$in( )$sup(s,3)$in( + )x$paren(0)$in( )s$in( - )1,$sup(s,4)$in( + )2$in( )$sup(s,3)$in( + )$sup(s,2)$in( + )2$in( )s)$close(])
(c75) (clearscreen(),
disp(" CALCULUS . . . Laplace and Fourier Transforms "),
disp(" Laplace transform solution of an O.D.E., continued "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Laplace and Fourier Transforms
|$label(0,15,Times New Roman,) Laplace transform solution of an O.D.E.$, continued
(c76) /* Take the inverse Laplace transform. */
soln:ilt(part(soln,1,2),s,t);
|$label(0,15,Times New Roman,$(d76$))$q(sin$paren(t),5)$hinge()$in( + )$q(2$in( )cos$paren(t),5)$hinge()$in( + )$q($paren(10$in( )x$paren(0)$in( + )1,$(,$))$in( )$sup($e(),$in( - )2$in( )t),10)$hinge()$in( - )$q(1,2)
(c77) /* Insert the initial condition. */
soln:subst(1,x(0),soln);
|$label(0,15,Times New Roman,$(d77$))$q(sin$paren(t),5)$hinge()$in( + )$q(2$in( )cos$paren(t),5)$hinge()$in( + )$q(11$in( )$sup($e(),$in( - )2$in( )t),10)$hinge()$in( - )$q(1,2)
(c78) (equalscale:false,ymax:1,ymin:-1,
plot(soln,t,0,10,time,amplitude,"X(t) versus time") )$
(c79) (remvalue(eq,lt_eq,soln,ymax,ymin), reset(derivabbrev,equalscale),
clearscreen(),
if get('fourier,'version)=false then load("fourier"),
disp(" CALCULUS . . . Laplace and Fourier Transforms, continued ") )$
|$label(0,15,Times New Roman,) CALCULUS . . . Laplace and Fourier Transforms$, continued
(c80) /* Example: Fourier transform of rectified sine wave */
ft:fourier(abs(sin(t)),t,%pi);
|$label(0,15,Times New Roman,$(e80$))$sub(a,0)$hinge()$in( = )$q(2,$greektext(p))
|$label(0,15,Times New Roman,$(e81$))$sub(a,%nn)$hinge()$in( = )$in( - )$q(2$in( )$sup($paren($in( - )1,$(,$)),%nn)$in( + )2,$greektext(p)$in( )$paren($sup(%nn,2)$in( - )1,$(,$)))
|$label(0,15,Times New Roman,$(e82$))$sub(b,%nn)$hinge()$in( = )0
|$label(0,15,Times New Roman,$(d82$))$open([)e80$ina($, )$hinge()e81$ina($, )$hinge()e82$close(])
(c83) fourexpand(ft,t,%pi,inf);
|$label(0,15,Times New Roman,$(d83$))$q(2,$greektext(p))$hinge()$in( - )$q($sum($q($paren(2$in( )$sup($paren($in( - )1,$(,$)),%nn)$in( + )2,$(,$))$in( )cos$paren(%nn$in( )t),$sup(%nn,2)$in( - )1),%nn = 1,$greektext(Ñ)),$greektext(p))
(c84) (remvalue(ft),
clearscreen(),
disp(dpart(" CALCULUS . . . Ordinary Differential Equations ")),
disp(" Example: Solve a second-order initial value problem. ") )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Ordinary Differential Equations )
|$label(0,15,Times New Roman,) Example: Solve a second-order initial value problem.
(c85) (depends(y,x),eq:diff(y,x,2)+b*y*diff(y,x)^2=0);
|$label(0,15,Times New Roman,$(d85$))$q($sup(d,2)y,d$sup(x,2))$hinge()$in( + )b$in( )y$in( )$sup($paren($q(dy,dx),$(,$)),2)$hinge()$in( = )0
(c86) gen_soln:ode(eq,y,x);
|$label(0,15,Times New Roman,$(d86$))$q($sqrt(2)$in( )$sqrt($greektext(p))$in( )erf$paren($q($sqrt($in( - )b)$in( )y,$sqrt(2))),2$in( )%k1$in( )$sqrt($in( - )b))$hinge()$in( = )x$hinge()$in( + )%k2
(c87) (clearscreen(),
disp(" CALCULUS . . . Ordinary Differential Equations "),
disp(" Example: Second-order initial value problem, continued "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Ordinary Differential Equations
|$label(0,15,Times New Roman,) Example: Second-order initial value problem$, continued
(c88) spec_soln:ratsimp(ic2(gen_soln,x=0,y=0,'diff(y,x)=2));
|$label(0,15,Times New Roman,$(d88$))$q($sqrt(2)$in( )$sqrt($greektext(p))$in( )$sup($e(),$in( - )$q(b$in( )$sup(y,2),2))$in( )erf$paren($q($sqrt($in( - )b)$in( )y,$sqrt(2))),4$in( )$sqrt($in( - )b))$hinge()$in( = )x
(c89) /* Macsyma will tell you what method it used. */
method;
|$label(0,15,Times New Roman,$(d89$))freeofx
(c90) (clearscreen(),
disp(" CALCULUS . . . Ordinary Differential Equations, continued "),
disp(" Example: Solve a second-order boundary value problem. "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Ordinary Differential Equations$, continued
|$label(0,15,Times New Roman,) Example: Solve a second-order boundary value problem.
(c91) /* Use the same O.D.E. as above, with boundary conditions. */
(assume(b<0),spec_soln:bc2(gen_soln,x=0,y=1,x=1,y=3));
|$label(0,15,Times New Roman,$(d91$))$q($sqrt(2)$in( )$sqrt($greektext(p))$in( )erf$paren($q($sqrt($in( - )b)$in( )y,$sqrt(2))),$sqrt(2)$in( )$sqrt($greektext(p))$in( )erf$paren($q(3$in( )$sqrt($in( - )b),$sqrt(2)))$in( - )$sqrt(2)$in( )$sqrt($greektext(p))$in( )erf$paren($q($sqrt($in( - )b),$sqrt(2))))$hinge()$in( = )x$hinge()$in( + )$q(erf$paren($q($sqrt(2)$in( )$sqrt($in( - )b),2)),erf$paren($q(3$in( )$sqrt(2)$in( )$sqrt($in( - )b),2))$in( - )erf$paren($q($sqrt(2)$in( )$sqrt($in( - )b),2)))
(c92) (clearscreen(),
disp(" CALCULUS . . . Ordinary Differential Equations "),
disp(" Example: Second-order boundary value problem, continued "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Ordinary Differential Equations
|$label(0,15,Times New Roman,) Example: Second-order boundary value problem$, continued
(c93) /* Solve the implicit relation given above for Y(X). */
solve(spec_soln,y);
|$label(0,15,Times New Roman,$(d93$))$open([)erf$paren($q($sqrt($in( - )b)$in( )y,$sqrt(2)))$hinge()$in( = )$in( - )$q(erf$paren($q(3$in( )$sqrt($in( - )b),$sqrt(2)))$in( )$paren(erf$paren($q(3$in( )$sqrt(2)$in( )$sqrt($in( - )b),2))$in( )x$in( + )erf$paren($q($sqrt(2)$in( )$sqrt($in( - )b),2))$in( )$paren(1$in( - )x,$(,$)),$(,$))$in( + )erf$paren($q($sqrt($in( - )b),$sqrt(2)))$in( )$paren(erf$paren($q($sqrt(2)$in( )$sqrt($in( - )b),2))$in( )$paren(x$in( - )1,$(,$))$in( - )erf$paren($q(3$in( )$sqrt(2)$in( )$sqrt($in( - )b),2))$in( )x,$(,$)),erf$paren($q($sqrt(2)$in( )$sqrt($in( - )b),2))$in( - )erf$paren($q(3$in( )$sqrt(2)$in( )$sqrt($in( - )b),2)))$close(])
(c94) (remvalue(eq,gen_soln,spec_soln), remove(y,dependency),
clearscreen(),
if get('inteqn,'version)=false then load("inteqn"),
disp(dpart(" CALCULUS . . . Integral Equations ")) )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Integral Equations )
(c95) /* Example: Solve an integral equation of the second kind.
*/
(assume(x>0), eq: p(x)-'integrate(x*u*p(u),u,0,x)-exp(-x)*(1+x+x^2)+x);
|$label(0,15,Times New Roman,$(d95$))p$paren(x)$hinge()$in( - )$paren($sup(x,2)$in( + )x$in( + )1,$(,$))$in( )$sup($e(),$in( - )x)$hinge()$in( - )$paren($integrate(u$in( )p$paren(u),u,0,x),$(,$))$in( )x$hinge()$in( + )x
(c96) ieqn(eq,p(x),vlfrnk)$
|$label(-1,15,Times New Roman,)Default 4th arg$, number of iterations or coll. parms.: $in() $in()1
|$label(-1,15,Times New Roman,)Default 5th arg$, initial guess: $in() $in()none
|$label(0,15,Times New Roman,$(e96$))$open([)$sup($e(),$in( - )x)$ina($, )$hinge()vlfrnk$close(])
(c97) (clearscreen(),
disp(" CALCULUS . . . Integral Equations, continued ") )$
|$label(0,15,Times New Roman,) CALCULUS . . . Integral Equations$, continued
(c98) /* Example: Solve two coupled integral equations of the second kind.
*/
eq:[p(x)='integrate(x*u*p(u)*q(u),u,0,2),q(x)='integrate(x^2*u^2*q(u)+x*u*p(u),u,1,2)];
|$label(0,15,Times New Roman,$(d98$))$open([)p$paren(x)$hinge()$in( = )$open($()$integrate(u$in( )p$paren(u)$in( )q$paren(u),u,0,2)$close($))$hinge()$in( )x$ina($, )$hinge()q$paren(x)$hinge()$in( = )$integrate($open($()$sup(u,2)$in( )q$paren(u)$in( )$sup(x,2)$hinge()$in( + )u$in( )p$paren(u)$in( )x$close($)),u,1,2)$close(])
(c99) ieqn(eq,[p(x),q(x)],flfrnk2nd)$
|$label(-1,15,Times New Roman,)Default 4th arg$, number of iterations or coll. parms.: $in() $in()1
|$label(-1,15,Times New Roman,)Default 5th arg$, initial guess: $in() $in()none
|$label(0,15,Times New Roman,$(e99$))$open([)$open([)0$ina($, )$hinge()0$close(])$ina($, )$hinge()flfrnk2nd$close(])
|$label(0,15,Times New Roman,$(e100$))$open([)$open([)$in( - )$q(39$in( )x,56)$ina($, )$hinge()$q(75$in( )$sup(x,2),64)$hinge()$in( - )$q(13$in( )x,8)$close(])$ina($, )$hinge()flfrnk2nd$close(])
(c101) (remvalue(eq),forget(x>0),
clearscreen(),
if get('vect,'version)=false then load("vect"),
disp(dpart(" CALCULUS . . . Vector Analysis ")),
disp(" Some vector identities and simplifications ") )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Vector Analysis )
|$label(0,15,Times New Roman,) Some vector identities and simplifications
(c102) (declare([b,d,e,h,j], nonscalar), depends([b,d,e,h,j,rho],t))$
(c103) div(curl(b));
|$label(0,15,Times New Roman,$(d103$))0
(c104) (expandall:true,vectorsimp(j~(e~b)));
|$label(0,15,Times New Roman,$(d104$))$paren(b$in( . )j,$(,$))$in( )e$hinge()$in( - )b$in( )$paren(e$in( . )j,$(,$))
(c105) vectorsimp(curl(curl(b)));
|$label(0,15,Times New Roman,$(d105$))grad div b$hinge()$in( - )laplacian b
(c106) (expandall:false,
clearscreen(),
disp(" CALCULUS . . . Vector Analysis, continued "),
disp(" Example: Maxwell's equations "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Vector Analysis$, continued
|$label(0,15,Times New Roman,) Example: Maxwell's equations
(c107) expr1: curl(e) + diff(b,t);
|$label(0,15,Times New Roman,$(d107$))curl e$hinge()$in( + )$q(db,dt)
(c108) expr2: div(b);
|$label(0,15,Times New Roman,$(d108$))div b
(c109) expr3: curl(h) - diff(d,t)-j;
|$label(0,15,Times New Roman,$(d109$))$in( - )j$hinge()$in( + )curl h$hinge()$in( - )$q(dd,dt)
(c110) expr4: div(d) - rho;
|$label(0,15,Times New Roman,$(d110$))div d$hinge()$in( - )$greektext(r)
(c111) (clearscreen(),
disp(" CALCULUS . . . Vector Analysis "),
disp(" Maxwell's equations, continued "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Vector Analysis
|$label(0,15,Times New Roman,) Maxwell's equations$, continued
(c112) /* Express the third equation in cylindrical coordinates.
*/
(scalefactors([[r*cos(theta),r*sin(theta),z],r,theta,z]),
depends([b,d,e,h,j,rho],[r,theta,z]))$
(c113) (eq3:express(expr3),eq3:ev(eq3,diff));
|$label(0,15,Times New Roman,$(d113$))$open([)$q($q(d,d$greektext(q))$paren($sub(h,z))$in( - )$paren(r,|,|)$in( )$q(d,dz)$paren($sub(h,$greektext(q))),$paren(r,|,|))$hinge()$in( - )$q(d,dt)$paren($sub(d,r))$hinge()$in( - )$sub(j,r)$ina($, )$hinge()$in( - )$q(d,dr)$paren($sub(h,z))$hinge()$in( - )$q(d,dt)$paren($sub(d,$greektext(q)))$hinge()$in( - )$sub(j,$greektext(q))$hinge()$in( + )$q(d,dz)$paren($sub(h,r))$ina($, )$hinge()$in( - )$q(d,dt)$paren($sub(d,z))$hinge()$in( - )$sub(j,z)$hinge()$in( + )$q($paren(r,|,|)$in( )$q(d,dr)$paren($sub(h,$greektext(q)))$in( + )$q($paren(r,|,|)$in( )$sub(h,$greektext(q)),r)$in( - )$q(d,d$greektext(q))$paren($sub(h,r)),$paren(r,|,|))$close(])
(c114) (clearscreen(),
if get('fdif_pde,'version)=false then load("fdif_pde"),
disp(" CALCULUS . . . Finite Difference Equations "),
disp(" Maxwell's equations, continued "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Finite Difference Equations
|$label(0,15,Times New Roman,) Maxwell's equations$, continued
(c115) /* Generate finite difference equation for radial component of equation 3.
*/
deq:difference_pde(part(eq3,1),[d[r],h[th],h[z],j[r]],[r,th,z],
[dr,hth,hz,jr],[delr,delth,delz],'central,t,delt,'exp_euler);
|$label(0,15,Times New Roman,$(d115$))$q($q(d,d$greektext(q))$paren($sub(hz,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4))$in( - )$paren($sub(r,n1),|,|)$in( )$q(d,d$sub(z,n3))$paren($sub(h,$greektext(q))),$paren($sub(r,n1),|,|))$hinge()$in( - )$q($sub(dr,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4$in( + )1)$in( - )$sub(dr,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4),delt)$hinge()$in( - )$sub(jr,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4)
(c116) (clearscreen(),
disp(" CALCULUS . . . Finite Difference Equations "),
disp(" Maxwell's equations, continued "))$
|$label(0,15,Times New Roman,) CALCULUS . . . Finite Difference Equations
|$label(0,15,Times New Roman,) Maxwell's equations$, continued
(c117) /* Solve for future-time variable and translate to Fortran.
*/
sol:solve(deq,dr[n1,n2,n3,n4+1]);
|$label(0,15,Times New Roman,$(d117$))$open([)$sub(dr,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4$in( + )1)$hinge()$in( = )$in( - )$q(delt$in( )$paren($sub(r,n1),|,|)$in( )$q(d,d$sub(z,n3))$paren($sub(h,$greektext(q)))$in( - )delt$in( )$q(d,d$greektext(q))$paren($sub(hz,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4))$in( + )$paren(delt$in( )$sub(jr,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4)$in( - )$sub(dr,n1$ina($, )$hinge()n2$ina($, )$hinge()n3$ina($, )$hinge()n4),$(,$))$in( )$paren($sub(r,n1),|,|),$paren($sub(r,n1),|,|))$close(])
(c118) fortran(first(sol))$
DR(N1,N2,N3,N4+1) = -(DELT*ABS(R(N1))*'DIFF(H(THETA),Z(N3),1)-DELT
1 *'DIFF(HZ(N1,N2,N3,N4),THETA,1)+(DELT*JR(N1,N2,N3,N4)-DR(N1,N2,
2 N3,N4))*ABS(R(N1)))/ABS(R(N1))
(c119) (remvalue(deq,eq3,expr1,expr2,expr3,expr4,sol),
remove(".",commutative,[b,d,e,h,j,rho],dependency,[b,d,e,h,j], nonscalar),
clearscreen(),kill(chr2,g,lg,mcs,ug),
if get('itensor,'version)=false then load("itensor") else init_itensor(),
if get('ctensor,'version)=false then load("ctensor") else clear_ctensor(),
disp(dpart(" CALCULUS . . . Tensor Analysis ")),
disp("Example: Hydrodynamic equations in covariant form") )$
|$label(0,15,Times New Roman,)$box( CALCULUS . . . Tensor Analysis )
|$label(0,15,Times New Roman,)Example: Hydrodynamic equations in covariant form
(c120) /* Define metric, mass density, velocity, flow, stress tensors.
*/
(imetric(g),
depends([dens,vel],t),
components(flow([],[i]),dens([],[])*vel([],[i])),
components(strs([],[i,j]),dens([],[])*vel([],[i])*vel([],[j])
+pres([],[])*g([],[i,j])))$
(c121) /* Write the momentum conservation equation.
*/
ishow(momentum_eq: diff(flow([],[i]),t)
+ canform(rename(covdiff(strs([],[i,j]),j))));
|$label(0,15,Times New Roman,$(d121$))dens$in( )$sup(vel,%1)$in( )$sup(vel,%2)$in( )$sup($sub(ichr2,%1 %2),i)$hinge()$in( + )pres$in( )$sup(g,%1$in( )%2)$in( )$sup($sub(ichr2,%1 %2),i)$hinge()$in( + )pres$in( )$sup(g,%1$in( )i)$in( )$sup($sub(ichr2,%1 %2),%2)$hinge()$in( + )dens$in( )$sup(vel,%2)$in( )$sup(vel,i)$in( )$sup($sub(ichr2,%1 %2),%1)$hinge()$in( + )dens$in( )$q(d,dt)$paren($sup(vel,i))$hinge()$in( + )$sup(vel,i)$in( )$q(ddens,dt)$hinge()$in( + )dens$in( )$sup(vel,%1)$in( )$sup($sub(vel,$,%1),i)$hinge()$in( + )dens$in( )$sup($sub(vel,$,%1),%1)$in( )$sup(vel,i)$hinge()$in( + )$sub(dens,$,%1)$in( )$sup(vel,%1)$in( )$sup(vel,i)$hinge()$in( + )pres$in( )$sup($sub(g,$,%1),%1$in( )i)$hinge()$in( + )$sub(pres,$,%1)$in( )$sup(g,%1$in( )i)
(c122) clearscreen()$
(c123) /* Convert the momentum equation to component tensor form. */
mom_macs: ic_convert(mom([],[i])=momentum_eq);
|$label(0,15,Times New Roman,$(d123$))for i thru dimf do $sub(mom,i)$hinge()$in( : )dens$in( )sum$paren(sum$paren($sub(vel,%1)$in( )$sub(vel,%2)$in( )$sub(mcs,%1$ina($, )%2$ina($, )i)$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$ina($, )$hinge()%2$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )pres$in( )sum$paren(sum$paren($sub(ug,%1$ina($, )%2)$in( )$sub(mcs,%1$ina($, )%2$ina($, )i)$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$ina($, )$hinge()%2$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )pres$in( )sum$paren(sum$paren($sub(ug,%1$ina($, )i)$in( )$sub(mcs,%1$ina($, )%2$ina($, )%2)$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$ina($, )$hinge()%2$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )dens$in( )$sub(vel,i)$in( )sum$paren(sum$paren($sub(vel,%2)$in( )$sub(mcs,%1$ina($, )%2$ina($, )%1)$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$ina($, )$hinge()%2$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )dens$in( )$q(d,dt)$paren($sub(vel,i))$hinge()$in( + )$sub(vel,i)$in( )$q(ddens,dt)$hinge()$in( + )dens$in( )sum$paren($sub(vel,%1)$in( )diff$paren($sub(vel,i)$ina($, )$hinge()$sub($greektext(w),%1))$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )dens$in( )$sub(vel,i)$in( )sum$paren(diff$paren($sub(vel,%1)$ina($, )$hinge()$sub($greektext(w),%1))$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )$sub(vel,i)$in( )sum$paren(diff$paren(dens$ina($, )$hinge()$sub($greektext(w),%1))$in( )$sub(vel,%1)$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )pres$in( )sum$paren(diff$paren($sub(ug,%1$ina($, )i)$ina($, )$hinge()$sub($greektext(w),%1))$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)$hinge()$in( + )sum$paren(diff$paren(pres$ina($, )$hinge()$sub($greektext(w),%1))$in( )$sub(ug,%1$ina($, )$hinge()i)$ina($, )$hinge()%1$ina($, )$hinge()1$ina($, )$hinge()dimf)
(c124) (clearscreen(),
disp(" CALCULUS . . . Tensor Analysis "),
disp(" Hydrodynamics, continued ") )$
|$label(0,15,Times New Roman,) CALCULUS . . . Tensor Analysis
|$label(0,15,Times New Roman,) Hydrodynamics$, continued
(c125) /* Now specify a metric ... use 3-d spherical coordinates.
*/
(dim:3,omega:[r,theta,phi], depends([dens,pres,vel],[r,theta,phi,t]),
lg:matrix([1,0,0],[0,omega[1]^2,0],[0,0,omega[1]^2*sin(omega[2])^2]),
ev(ug:invert(lg),ratsimp),christof(false),lg);
|$label(0,15,Times New Roman,$(d125$))$matrix(3,3,1,0,0,0,$sup(r,2),0,0,0,$sup(r,2)$in( )$sup(sin,2)$paren($greektext(q)))
(c126) (clearscreen(),
disp(" CALCULUS . . . Tensor Analysis "),
disp(" Hydrodynamics, continued ") )$
|$label(0,15,Times New Roman,) CALCULUS . . . Tensor Analysis
|$label(0,15,Times New Roman,) Hydrodynamics$, continued
(c127) /* Express one of the momentum equations in these coordinates.
*/
(''mom_macs,mom[1]);
|$label(0,15,Times New Roman,$(d127$))dens$in( )$paren($in( - )$sup($sub(vel,3),2)$in( )r$in( )$sup(sin,2)$paren($greektext(q))$in( - )$sup($sub(vel,2),2)$in( )r,$(,$))$hinge()$in( + )$sub(vel,1)$in( )dens$in( )$paren($q($sub(vel,2)$in( )cos$paren($greektext(q)),sin$paren($greektext(q)))$in( + )$q(2$in( )$sub(vel,1),r),$(,$))$hinge()$in( + )$q(dpres,dr)$hinge()$in( + )$sub(vel,1)$in( )$paren($sub(vel,2)$in( )$q(ddens,d$greektext(q))$in( + )$sub(vel,1)$in( )$q(ddens,dr)$in( + )$sub(vel,3)$in( )$q(ddens,d$greektext(f)),$(,$))$hinge()$in( + )$sub(vel,1)$in( )$q(ddens,dt)$hinge()$in( + )$sub(vel,1)$in( )$paren($q(d,d$greektext(f))$paren($sub(vel,3))$in( + )$q(d,d$greektext(q))$paren($sub(vel,2))$in( + )$q(d,dr)$paren($sub(vel,1)),$(,$))$in( )dens$hinge()$in( + )$paren($sub(vel,2)$in( )$q(d,d$greektext(q))$paren($sub(vel,1))$in( + )$sub(vel,1)$in( )$q(d,dr)$paren($sub(vel,1))$in( + )$sub(vel,3)$in( )$q(d,d$greektext(f))$paren($sub(vel,1)),$(,$))$in( )dens$hinge()$in( + )$q(d,dt)$paren($sub(vel,1))$in( )dens
(c128) /* Express the forcing terms of the equation in Fortran.
*/
fortran(part(mom[1],[1,2]))$
DENS*(-VEL(3)**2*R*SIN(THETA)**2-VEL(2)**2*R)+VEL(1)*DENS*(VEL(2)*
1 COS(THETA)/SIN(THETA)+2*VEL(1)/R)
(c129) (remvalue(lg,mom_macs,momentum_eq,omega,ug),remove([dens,vel],dependency),
init_itensor(), remarray(mom),
clearscreen(),
disp(dpart(" SYMBOLIC APPROXIMATION METHODS ")),
disp(" "),
disp(" Taylor Series "),
disp(" "),
disp(" Pade Approximations "),
disp(" "),
disp(" Perturbation Solutions of O.D.E.'s ") )$
|$label(0,15,Times New Roman,)$box( SYMBOLIC APPROXIMATION METHODS )
|$label(0,15,Times New Roman,)
|$label(0,15,Times New Roman,) Taylor Series
|$label(0,15,Times New Roman,)
|$label(0,15,Times New Roman,) Pade Approximations
|$label(0,15,Times New Roman,)
|$label(0,15,Times New Roman,) Perturbation Solutions of O.D.E.'s
(c130) (clearscreen(),
disp(dpart(" SYMBOLIC APPROXIMATION METHODS . . . Taylor Series ")) )$
|$label(0,15,Times New Roman,)$box( SYMBOLIC APPROXIMATION METHODS . . . Taylor Series )
(c131) f(x,y):=atan(sqrt(a*x^2+b*y));
|$label(0,15,Times New Roman,$(d131$))f$paren(x$ina($, )$hinge()y)$hinge()$in( := )atan$paren($sqrt(a$in( )$sup(x,2)$in( + )b$in( )y))
(c132) taylor(f(x,y),x,0,4,y,0,4);
|$label(0,15,Times New Roman,$(d132$) /T/ )$sqrt(b)$in( )$sqrt(y)$in( - )$q($sqrt(b)$in( )b$in( )$sup(y,3$in(/)2),3)$in( + )$q($sqrt(b)$in( )$sup(b,2)$in( )$sup(y,5$in(/)2),5)$in( - )$q($sqrt(b)$in( )$sup(b,3)$in( )$sup(y,7$in(/)2),7)$in( + ). . .$hinge()$in( + )$paren($in( - )$q($sqrt(b)$in( )$sup(b,2)$in( )a$in( )$sup(y,5$in(/)2),2)$in( + )$q($sqrt(b)$in( )b$in( )a$in( )$sup(y,3$in(/)2),2)$in( - )$q($sqrt(b)$in( )a$in( )$sqrt(y),2)$in( + )$q($sqrt(b)$in( )a,2$in( )b$in( )$sqrt(y))$in( + ). . .,$(,$))$in( )$sup(x,2)$hinge()$in( + )$paren($in( - )$q(5$in( )$sqrt(b)$in( )b$in( )$sup(a,2)$in( )$sup(y,3$in(/)2),8)$in( + )$q(3$in( )$sqrt(b)$in( )$sup(a,2)$in( )$sqrt(y),8)$in( - )$q($sqrt(b)$in( )$sup(a,2),8$in( )b$in( )$sqrt(y))$in( - )$q($sup(a,2),8$in( )$sqrt(b)$in( )b$in( )$sup(y,3$in(/)2))$in( + ). . .,$(,$))$in( )$sup(x,4)$in( + ). . .
(c133) (remfunction(f),
clearscreen(),
disp(" SYMBOLIC APPROXIMATION METHODS . . . Taylor Series, continued "),
disp(" Example: Approximate Taylor solution of an implicit equation ") )$
|$label(0,15,Times New Roman,) SYMBOLIC APPROXIMATION METHODS . . . Taylor Series$, continued
|$label(0,15,Times New Roman,) Example: Approximate Taylor solution of an implicit equation
(c134) curve3:-x-2*x^2*y+y^3;
|$label(0,15,Times New Roman,$(d134$))$sup(y,3)$hinge()$in( - )2$in( )$sup(x,2)$in( )y$hinge()$in( - )x
(c135) taylor_solve(curve3,y,x,0,[3]);
|$label(0,15,Times New Roman,$(d135$) /T/ )$open([)$open([)y$hinge()$in( = )k0$in( )$sup(x,1$in(/)3)$hinge()$in( + )$q(2$in( )$sup(x,5$in(/)3),3$in( )k0)$hinge()$in( - )$q(8$in( )$sup(x,13$in(/)3),81$in( )$sup(k0,2))$in( + ). . .$ina($, )$hinge()$sup(k0,3)$hinge()$in( = )1$close(])$close(])
(c136) (remvalue(curve3),
clearscreen(),
disp(" SYMBOLIC APPROXIMATION METHODS . . . Taylor Series, continued "),
disp(" Example: Find taylor solution of coupled O.D.E.'s. ") )$
|$label(0,15,Times New Roman,) SYMBOLIC APPROXIMATION METHODS . . . Taylor Series$, continued
|$label(0,15,Times New Roman,) Example: Find taylor solution of coupled O.D.E.'s.
(c137) eq:['diff(x,t,2)=c*x*y,'diff(y,t,2)=tan(x)+%e^(t*'diff(y,t))];
|$label(0,15,Times New Roman,$(d137$))$open([)$q($sup(d,2)x,d$sup(t,2))$hinge()$in( = )c$hinge()$in( )x$hinge()$in( )y$ina($, )$hinge()$q($sup(d,2)y,d$sup(t,2))$hinge()$in( = )$sup($e(),t$in( )$q(dy,dt))$hinge()$in( + )tan$paren(x)$close(])
(c138) /* Use initial conditions X(0)=A, X'(0)=0, Y(0)=B, Y'(0)=3 .
*/
taylor_ode(eq,[x,y],t,3,[0,[a,0],[b,3]]);
|$label(0,15,Times New Roman,$(d138$) /T/ )$open([)$open([)x$hinge()$in( = )a$hinge()$in( + )$q(a$in( )b$in( )c$in( )$sup(t,2),2)$hinge()$in( + )$q(a$in( )c$in( )$sup(t,3),2)$in( + ). . .$ina($, )$hinge()y$hinge()$in( = )b$hinge()$in( + )3$in( )t$hinge()$in( + )$q($paren(tan$paren(a)$in( + )1,$(,$))$in( )$sup(t,2),2)$hinge()$in( + )$q($sup(t,3),2)$in( + ). . .$close(])$close(])
(c139) (remvalue(eq),
clearscreen(),
disp(dpart(" SYMBOLIC APPROXIMATION METHODS . . . Pade Approximations ")),
disp(" Example: Compute Pade approximation of a function. ") )$
|$label(0,15,Times New Roman,)$box( SYMBOLIC APPROXIMATION METHODS . . . Pade Approximations )
|$label(0,15,Times New Roman,) Example: Compute Pade approximation of a function.
(c140) /* A Pade approximation to F(X) is a rational function R(X)
which has the same taylor series, up to some order. */
ft:taylor(tan(x),x,0,8);
|$label(0,15,Times New Roman,$(d140$) /T/ )x$hinge()$in( + )$q($sup(x,3),3)$hinge()$in( + )$q(2$in( )$sup(x,5),15)$hinge()$in( + )$q(17$in( )$sup(x,7),315)$in( + ). . .
(c141) fp:pade(ft,4,4);
|$label(0,15,Times New Roman,$(d141$))$open([)$in( - )$q(10$in( )$sup(x,3)$in( - )105$in( )x,$sup(x,4)$in( - )45$in( )$sup(x,2)$in( + )105)$close(])
(c142) (fp:part(fp,1),taylor(fp,x,0,8));
|$label(0,15,Times New Roman,$(d142$) /T/ )x$hinge()$in( + )$q($sup(x,3),3)$hinge()$in( + )$q(2$in( )$sup(x,5),15)$hinge()$in( + )$q(17$in( )$sup(x,7),315)$in( + ). . .
(c143) (clearscreen(),
disp(dpart(" SYMBOLIC APPROXIMATION METHODS . . . Pade Approximations ")),
disp(" Pade approximations, continued ") )$
|$label(0,15,Times New Roman,)$box( SYMBOLIC APPROXIMATION METHODS . . . Pade Approximations )
|$label(0,15,Times New Roman,) Pade approximations$, continued
(c144) /*
Plot the results.
*/
(equalscale:false,ymin:-10,ymax:10,
plot([tan(x),fp,ft],x,%pi/4,3*%pi/4,[0,2,4],false,false,
"TAN(X) (solid), Pade approximation(4,4) of TAN(X) (dashed),
and Taylor series(8) for TAN(X) (dot-dash)") )$
(c145) (remvalue(fp,ft,ymin,ymax),reset(equalscale),
clearscreen(),
if get('lindstedt,'version)=false then load("lindst"),
disp(dpart(" SYMBOLIC APPROXIMATION METHODS . . . Perturbation Solutions of O.D.E.'s ")),
disp(" Example: Perturbation solution of an almost-harmonic oscillator ") )$
|$label(0,15,Times New Roman,)$box( SYMBOLIC APPROXIMATION METHODS . . . Perturbation Solutions of O.D.E.'s )
|$label(0,15,Times New Roman,) Example: Perturbation solution of an almost-harmonic oscillator
(c146) depends(y,t)$
(c147) eq:diff(y,t,2)+w^2*y+e*y^3;
|$label(0,15,Times New Roman,$(d147$))$q($sup(d,2)y,d$sup(t,2))$hinge()$in( + )e$in( )$sup(y,3)$hinge()$in( + )$sup(w,2)$in( )y
(c148) /*
where:
Y(T)= Amplitude of the oscillator
W = Angular frequency of the linearized oscillator
e = Coefficient for cubic force term << 1 .
The initial conditions are: Y(0) = A, Y'(0)= 0 .
*/
disp(" ")$
|$label(0,15,Times New Roman,)
(c149) (clearscreen(),
disp(" SYMBOLIC APPROXIMATION METHODS . . . Perturbation Solutions of O.D.E.'s "),
disp(" Almost-harmonic oscillator, continued ") )$
|$label(0,15,Times New Roman,) SYMBOLIC APPROXIMATION METHODS . . . Perturbation Solutions of O.D.E.'s
|$label(0,15,Times New Roman,) Almost-harmonic oscillator$, continued
(c150) /* Lindstedt's method finds the approximate solution
and the perturbed frequency, to second order in e.
*/
lindstedt(eq,e,2,[a,0]);
|$label(0,15,Times New Roman,$(d150$))$open([)$open([)$open([)$q($paren(cos$paren(3$in( )%tau)$in( - )cos$paren(%tau),$(,$))$in( )$sup(a,3)$in( )e,32$in( )$sup(w,2))$hinge()$in( + )$q($paren(cos$paren(5$in( )%tau)$in( - )24$in( )cos$paren(3$in( )%tau)$in( + )23$in( )cos$paren(%tau),$(,$))$in( )$sup(a,5)$in( )$sup(e,2),1024$in( )$sup(w,4))$hinge()$in( + )cos$paren(%tau)$in( )a$close(])$ina($, )$hinge()%tau$hinge()$in( = )t$hinge()$in( )$open($()$q(3$in( )$sup(a,2)$in( )e,8$in( )$sup(w,2))$hinge()$in( - )$q(21$in( )$sup(a,4)$in( )$sup(e,2),256$in( )$sup(w,4))$hinge()$in( + )1$close($))$hinge()$in( )$paren(w,|,|)$close(])$close(])
(c151) (remvalue(eq), remove(y,dependency),
clearscreen(),
disp(dpart(" NUMERICAL ANALYSIS ")),
disp(" Several Types of Arithmetic "),
disp(" Numerical Integration "),
disp(" Numerical Solution of O.D.E.'s "),
disp(" Fast Fourier Transforms "),
disp(" Interpolation of Roots of Equations "),
disp(" Least Squares Fit of Curves to Data "),
disp(" Generate Fortran Expressions "),
disp(" Increase Numerical Efficiency ") )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS )
|$label(0,15,Times New Roman,) Several Types of Arithmetic
|$label(0,15,Times New Roman,) Numerical Integration
|$label(0,15,Times New Roman,) Numerical Solution of O.D.E.'s
|$label(0,15,Times New Roman,) Fast Fourier Transforms
|$label(0,15,Times New Roman,) Interpolation of Roots of Equations
|$label(0,15,Times New Roman,) Least Squares Fit of Curves to Data
|$label(0,15,Times New Roman,) Generate Fortran Expressions
|$label(0,15,Times New Roman,) Increase Numerical Efficiency
(c152) (clearscreen(),
disp(dpart(" NUMERICAL ANALYSIS . . . Several Types of Arithmetic ")),
disp(" Example: Evaluate numerically ill-conditioned expressions. ") )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Several Types of Arithmetic )
|$label(0,15,Times New Roman,) Example: Evaluate numerically ill-conditioned expressions.
(c153) (n1:10^30*sqrt(6)+1,n2:10^15*sqrt(2),n3:10^15*sqrt(3))$
(c154) /* Ordinary floating point arithmetic gives the wrong result. */
float(n1)-float(n2)*float(n3);
|$label(0,15,Times New Roman,$(d154$))1.20892e+24
(c155) /* Example: Macsyma's exact arithmetic gives the correct result.
*/
radcan(n1-n2*n3);
|$label(0,15,Times New Roman,$(d155$))1
(c156) /* Example: Macsyma's arbitrary precision floating point arithmetic
gives the correct result.
*/
(bfprecision:35,bfloat(n1)-bfloat(n2)*bfloat(n3));
|$label(0,15,Times New Roman,$(d156$))$num(1.0b0)
(c157) (clearscreen(),
disp(" NUMERICAL ANALYSIS . . . Several Types of Arithmetic, continued "),
disp(" Example: Complex arithmetic "))$
|$label(0,15,Times New Roman,) NUMERICAL ANALYSIS . . . Several Types of Arithmetic$, continued
|$label(0,15,Times New Roman,) Example: Complex arithmetic
(c158) /* Express ARCSIN(2) with exact complex arithmetic.
*/
n1:asin(2)=polarform(asin(2));
|$label(0,15,Times New Roman,$(d158$))asin$paren(2)$hinge()$in( = )$sqrt($sup(log,2)$paren($sqrt(3)$in( + )2)$in( + )$q($sup($greektext(p),2),4))$hinge()$in( )$sup($e(),$in( - )$italictext(i)$in( )atan$paren($q(2$in( )log$paren($sqrt(3)$in( + )2),$greektext(p))))
(c159) /* Derive some complex floating point representations.
*/
n2:n1,numer,demoivre,expand;
|$label(0,15,Times New Roman,$(d159$))$in( - )$italictext(i)$in( )log$paren(3.73205$in( )$italictext(i))$hinge()$in( = )1.5708$hinge()$in( - )1.31696$in( )$italictext(i)
(c160) rectform(n2);
|$label(0,15,Times New Roman,$(d160$))1.5708$hinge()$in( - )1.31696$in( )$italictext(i)$hinge()$in( = )1.5708$hinge()$in( - )1.31696$in( )$italictext(i)
(c161) (reset(bfprecision),remvalue(n1,n2,n3),
clearscreen(),
setup_autoload("qq",quanc8),
disp(dpart(" NUMERICAL ANALYSIS . . . Numerical Integration ")),
disp(" Example: Romberg numerical integration algorithm ") )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Numerical Integration )
|$label(0,15,Times New Roman,) Example: Romberg numerical integration algorithm
(c162) f(x):= 1/(x^5+x+1);
|$label(0,15,Times New Roman,$(d162$))f$paren(x)$hinge()$in( := )$q(1,$sup(x,5)$in( + )x$in( + )1)
(c163) /* Integrate F(X) from 0 to 1.5 . */ romberg(f,0,1.5);
|$label(0,15,Times New Roman,$(d163$))0.75294
(c164) /*
Example: Newton-Cotes quadrature
*/
(g(x):=(mode_declare(x,float),sin(1/x)),g(x));
|$label(0,15,Times New Roman,$(d164$))sin$paren($q(1,x))
(c165) quanc8('g,0.01,0.1);
|$label(0,15,Times New Roman,$(d165$))$in( - )0.00903
(c166) (remfunction(f,g),
clearscreen(),
if get('rugkut,'version)=false then load("rugkut"),
disp(dpart(" NUMERICAL ANALYSIS . . . Numerical Solution of O.D.E.'s ")),
disp(" Example: Pair of oscillators with non-linear coupling ") )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Numerical Solution of O.D.E.'s )
|$label(0,15,Times New Roman,) Example: Pair of oscillators with non-linear coupling
(c167) eqx : 'diff(x,t,2) + (1+y/3)*x = 0 ;
|$label(0,15,Times New Roman,$(d167$))x$in( )$paren($q(y,3)$in( + )1,$(,$))$hinge()$in( + )$q($sup(d,2)x,d$sup(t,2))$hinge()$in( = )0
(c168) eqy : 'diff(y,t,2) + (1-x/3)*y = 0 ;
|$label(0,15,Times New Roman,$(d168$))$q($sup(d,2)y,d$sup(t,2))$hinge()$in( + )$paren(1$in( - )$q(x,3),$(,$))$in( )y$hinge()$in( = )0
(c169) /* Specify initial conditions.
*/
(icx : [ 'at(x,t=0) = 5 , 'at('diff(x,t),t=0) = 0 ] ,
icy : [ 'at(y,t=0) = 0 , 'at('diff(y,t),t=0) = -1/4 ] )$
(c170) (clearscreen(),
disp(" NUMERICAL ANALYSIS . . . Numerical Solution of O.D.E.'s "),
disp(" Pair of oscillators with non-linear coupling, continued "))$
|$label(0,15,Times New Roman,) NUMERICAL ANALYSIS . . . Numerical Solution of O.D.E.'s
|$label(0,15,Times New Roman,) Pair of oscillators with non-linear coupling$, continued
(c171) rk:runge_kutta([eqx,eqy], ['x,'y], 't, append(icx,icy), 0,
ev(4*%pi,numer), 0.1) $
(c172) /* Plot X(T), Y(T) and their derivatives versus time. */
(equalscale:false, graph(assoc('t,rk), [assoc('x,rk),assoc('diff('x,t),rk),
assoc('y,rk),assoc('diff('y,t),rk)],[0,1,2,3],
"X (solid), X' (long dash), Y (short dash), Y' (dot)",
false, "Runge_Kutta Solution of Coupled Oscillators") )$
(c173) /* Phase space plot of [X(T),X'(T)] and [Y(T),Y'(T)] */
graph([assoc('x,rk),assoc('y,rk)],[assoc('diff('x,t),rk),
assoc('diff('y,t),rk)],[0,2],
"Phase space plot of X, X' (solid) AND Y, Y' (dashed)",
false,"Runge_Kutta Solution of Coupled Oscillators")$
(c174) (remvalue(eqx,eqy,icx,icy,rk), reset(equalscale),
clearscreen(),
if get('fft,'version)=false then load("fft"),
disp(dpart(" NUMERICAL ANALYSIS . . . Fast Fourier Transforms ")) )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Fast Fourier Transforms )
(c175) /* Specify input function `a' at 8 points. */
(array(aa,7),
fillarray(aa,[-1.0,2.0,4.0,5.0,6.0,8.0,7.0,6.0]))$
(c176) /* Fast Fourier transform */
(fft(complex,1,aa),listarray(aa));
|$label(0,15,Times New Roman,$(d176$))$open([)37.0$ina($, )$hinge()$in( - )7.94974$in( )$italictext(i)$hinge()$in( - )10.5355$ina($, )$hinge()$in( - )1.0$in( )$italictext(i)$hinge()$in( - )6.0$ina($, )$hinge()$in( - )1.94975$in( )$italictext(i)$hinge()$in( - )3.46447$ina($, )$hinge()$in( - )5.0$ina($, )$hinge()1.94974$in( )$italictext(i)$hinge()$in( - )3.46447$ina($, )$hinge()1.0$in( )$italictext(i)$hinge()$in( - )6.0$ina($, )$hinge()7.94975$in( )$italictext(i)$hinge()$in( - )10.5355$close(])
(c177) /* Fast sine transform (requires floating-point input) */
(fillarray(aa,[-1.0,2.0,4.0,5.0,6.0,8.0,7.0,6.0]),
sinfft(aa,1),listarray(aa));
|$label(0,15,Times New Roman,$(d177$))$open([)0.0$ina($, )$hinge()28.8501$ina($, )$hinge()$in( - )7.94974$ina($, )$hinge()4.19432$ina($, )$hinge()$in( - )1.0$ina($, )$hinge()0.63797$ina($, )$hinge()$in( - )1.94974$ina($, )$hinge()1.29373$close(])
(c178) (remarray(aa),
clearscreen(),
if get('bisect,'version)=false then load("bisect"),
disp(dpart(" NUMERICAL ANALYSIS . . . Iterative Solution of Equations ")) )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Iterative Solution of Equations )
(c179) /* Example : Newton's method */ eq: cos(x)^3 = x $
(c180) root: newton(eq,x,0.);
|$label(0,15,Times New Roman,$(d180$))$open([)x$hinge()$in( = )0.58244$close(])
(c181) eq, root;
|$label(0,15,Times New Roman,$(d181$))0.58244$hinge()$in( = )0.58244
(c182) /* Example : Root by bisection */ f(x) := sin(x)^2 - ''ev(1/%pi,numer) $
(c183) root : root_by_bisection('f,0,1);
|$label(0,15,Times New Roman,$(d183$))0.59945
(c184) f(root);
|$label(0,15,Times New Roman,$(d184$))0.0
(c185) (remvalue(eq,root),remfunction(f),
clearscreen(),
if get('lsq,'version)=false then load("lsq"),
disp(dpart(" NUMERICAL ANALYSIS . . . Least Squares Fit of Curves to Data ")) )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Least Squares Fit of Curves to Data )
(c186) /* Here are the abscissas and data values. */
(xlist:[0,1,2,3,4,5,6,7,8,9,10],
ylist:[-1,2,4,5,4.5,3,3.5,6,9,8,9.5])$
(c187) /* Linear regression */
fit1:lsq(xlist,ylist,1,'x);
|$label(0,15,Times New Roman,$(d187$))0.84091$in( )x$hinge()$in( + )0.65909
(c188) /* Fit with a cubic polynomial. */
fit3:lsq(xlist,ylist,3,'x);
|$label(0,15,Times New Roman,$(d188$))0.03108$in( )$sup(x,3)$hinge()$in( - )0.45862$in( )$sup(x,2)$hinge()$in( + )2.54293$in( )x$hinge()$in( - )0.34615
(c189) /* Plot the data and fitted curves. */
(equalscale:false,ymin:-2,
graph(xlist,ylist,[39],"Linear (solid) and cubic (dashed)",
false,"Linear and Cubic Polynomials Fitted to Data",first),
plot([fit1,fit3],x,0,10,[0,2],same,last))$
(c190) (remvalue(fit1,fit3,xlist,ylist,ymin),reset(equalscale),
clearscreen(),
disp(dpart(" NUMERICAL ANALYSIS . . . Generate Fortran Expressions ")),
disp(" Example: Convert to Fortran and optimize. ") )$
|$label(0,15,Times New Roman,)$box( NUMERICAL ANALYSIS . . . Generate Fortran Expressions )
|$label(0,15,Times New Roman,) Example: Convert to Fortran and optimize.
(c191) expr:expand(((c-d)^2-(a-1))*((c+d)^2+(a+1))*((a+1))^2);
|$label(0,15,Times New Roman,$(d191$))$sup(a,2)$in( )$sup(d,4)$hinge()$in( + )2$in( )a$in( )$sup(d,4)$hinge()$in( + )$sup(d,4)$hinge()$in( - )2$in( )$sup(a,2)$in( )$sup(c,2)$in( )$sup(d,2)$hinge()$in( - )4$in( )a$in( )$sup(c,2)$in( )$sup(d,2)$hinge()$in( - )2$in( )$sup(c,2)$in( )$sup(d,2)$hinge()$in( + )2$in( )$sup(a,2)$in( )$sup(d,2)$hinge()$in( + )4$in( )a$in( )$sup(d,2)$hinge()$in( + )2$in( )$sup(d,2)$hinge()$in( - )4$in( )$sup(a,3)$in( )c$in( )d$hinge()$in( - )8$in( )$sup(a,2)$in( )c$in( )d$hinge()$in( - )4$in( )a$in( )c$in( )d$hinge()$in( + )$sup(a,2)$in( )$sup(c,4)$hinge()$in( + )2$in( )a$in( )$sup(c,4)$hinge()$in( + )$sup(c,4)$hinge()$in( + )2$in( )$sup(a,2)$in( )$sup(c,2)$hinge()$in( + )4$in( )a$in( )$sup(c,2)$hinge()$in( + )2$in( )$sup(c,2)$hinge()$in( - )$sup(a,4)$hinge()$in( - )2$in( )$sup(a,3)$hinge()$in( + )2$in( )a$hinge()$in( + )1
(c192) fortran(expr)$
EXPR = A**2*D**4+2*A*D**4+D**4-2*A**2*C**2*D**2-4*A*C**2*D**2-2*C*
1 *2*D**2+2*A**2*D**2+4*A*D**2+2*D**2-4*A**3*C*D-8*A**2*C*D-4*A*C
2 *D+A**2*C**4+2*A*C**4+C**4+2*A**2*C**2+4*A*C**2+2*C**2-A**4-2*A
3 **3+2*A+1
(c193) /* Reduce the number of arithmetic operations by factoring. */
expr:factorsum(expr);
|$label(0,15,Times New Roman,$(d193$))$sup($paren(a$in( + )1,$(,$)),2)$hinge()$in( )$open($()$sup($paren(d$in( - )c,$(,$)),2)$hinge()$in( - )a$hinge()$in( + )1$close($))$hinge()$in( )$open($()$sup($paren(d$in( + )c,$(,$)),2)$hinge()$in( + )a$hinge()$in( + )1$close($))
(c194) fortran(expr)$
EXPR = (A+1)**2*((D-C)**2-A+1)*((D+C)**2+A+1)
(c195) (clearscreen(),
disp(" NUMERICAL ANALYSIS . . . Generate Fortran Expressions, continued "),
disp(" Example: Horner's method for optimizing rational functions ") )$
|$label(0,15,Times New Roman,) NUMERICAL ANALYSIS . . . Generate Fortran Expressions$, continued
|$label(0,15,Times New Roman,) Example: Horner's method for optimizing rational functions
(c196) expr:(7.4e8*x^3+1.0e-7*x^2-5.5*x+5.2e4)/(x^2+3.0e4*x-1.0e-6);
|$label(0,15,Times New Roman,$(d196$))$q(7.40001e+8$in( )$sup(x,3)$in( + )1.0e-7$in( )$sup(x,2)$in( - )5.5$in( )x$in( + )52000.0,$sup(x,2)$in( + )30000.0$in( )x$in( - )1.0e-6)
(c197) horner(expr,x),keepfloat:true;
|$label(0,15,Times New Roman,$(d197$))$q(x$in( )$paren(x$in( )$paren(7.40001e+8$in( )x$in( + )1.0e-7,$(,$))$in( - )5.5,$(,$))$in( + )52000.0,x$in( )$paren(1.0$in( )x$in( + )30000.0,$(,$))$in( - )1.0e-6)
(c198) (clearscreen(),
disp(" NUMERICAL ANALYSIS . . . Generate Fortran Expressions "),
disp(" Example: Optimize expressions for numerical analysis, continued "))$
|$label(0,15,Times New Roman,) NUMERICAL ANALYSIS . . . Generate Fortran Expressions
|$label(0,15,Times New Roman,) Example: Optimize expressions for numerical analysis$, continued
(c199) /* The OPTIMIZE command picks out repeated subexpressions. */
expr:sin(x^2+3*a^x)+(x^2+a^x)^2-log(x^2+3*a^x);
|$label(0,15,Times New Roman,$(d199$))sin$paren($sup(x,2)$in( + )3$in( )$sup(a,x))$hinge()$in( - )log$paren($sup(x,2)$in( + )3$in( )$sup(a,x))$hinge()$in( + )$sup($paren($sup(x,2)$in( + )$sup(a,x),$(,$)),2)
(c200) ex:optimize(expr);
|$label(0,15,Times New Roman,$(d200$))block$paren($paren(%1$ina($, )$hinge()%2$ina($, )$hinge()%3,[,])$ina($, )$hinge()%1$in( : )$sup(a,x)$ina($, )$hinge()%2$in( : )$sup(x,2)$ina($, )$hinge()%3$in( : )%2$in( + )3$in( )%1$ina($, )$hinge()sin$paren(%3)$in( - )log$paren(%3)$in( + )$sup($paren(%2$in( + )%1,$(,$)),2))
(c201) (fortran(part(ex,2)),fortran(part(ex,3)),fortran(part(ex,4)))$
%1=A**X
%2=X**2
%3=%2+3*%1
(c202) fortran(y=part(ex,5))$
Y = SIN(%3)-LOG(%3)+(%2+%1)**2
(c203) (remvalue(expr,ex),
clearscreen(),
disp(dpart(" GRAPHICS ")),
disp(" "),
disp(" 2-Dimensional Plotting "),
disp(" "),
disp(" 3-Dimensional Plotting ") )$
|$label(0,15,Times New Roman,)$box( GRAPHICS )
|$label(0,15,Times New Roman,)
|$label(0,15,Times New Roman,) 2-Dimensional Plotting
|$label(0,15,Times New Roman,)
|$label(0,15,Times New Roman,) 3-Dimensional Plotting
(c204) (clearscreen(),
disp(dpart(" GRAPHICS . . . 2-Dimensional Plotting ")) )$
|$label(0,15,Times New Roman,)$box( GRAPHICS . . . 2-Dimensional Plotting )
(c205) /* You have already seen examples of
o Ordinary 2 dimensional plots
- Eigenvalues
- Laplace transforms
- Pade approximations
o Plot of discrete list of numbers
- Runge-Kutta
Example: A two dimensional parametric plot
*/
(plotnum:200,paramplot(s*sin(s),s*cos(s),s,0,40,false,false,
"Parametric Plot of ( X = S*SIN(S) , Y = S*COS(S) )") )$
(c206) /*
Example: A two dimensional contour plot
*/
(equalscale:true,contours:8,labelcontours:true,plotnum0:plotnum1:25,
contourplot(y^2/2+cos(x)+x/2,x,-6,6,y,-3,3,false,false,
"Contour Plot of Z = X/2+COS(X)+Y^2/2"))$
(c207) (reset(equalscale,contours,labelcontours,plotnum),
clearscreen(),
disp(dpart(" GRAPHICS . . . 3-Dimensional Plotting ")),
disp(" Example: A three dimensional plot "),
disp(" ") )$
|$label(0,15,Times New Roman,)$box( GRAPHICS . . . 3-Dimensional Plotting )
|$label(0,15,Times New Roman,) Example: A three dimensional plot
|$label(0,15,Times New Roman,)
(c208) (equalscale:false,
plot3d(exp(-x^2-y^2)*x,x,-2,2,y,-1.5,2.5,false,false,
"Cartesian Plot of the Function EXP((-X^2-Y^2)*X)"))$
(c209) /*
Example: Different perspective on plot of the same function
*/
(viewpt:[-4,4,.5],equalscale:false,replot())$
(c210) (reset(viewpt,equalscale,plotnum0,plotnum1),
clearscreen(),
leftjust:true,disp(" IN CLOSING . . . "),
leftjust:false,disp(dpart(" MACSYMA CAN DO MUCH MORE THAN YOU HAVE SEEN HERE ")) )$
|$label(0,15,Times New Roman,) IN CLOSING . . .
|$label(0,15,Times New Roman,)$box( MACSYMA CAN DO MUCH MORE THAN YOU HAVE SEEN HERE )
(c211) /*
This demonstration only touches on the capabilities of Macsyma.
o Macsyma puts at your disposal over 1,500 documented commands,
predefined functions, option variables, data properties, and
system variables.
o You can write your own functions and programs.
o You can use Macsyma interactively or write batch programs,
performing both symbolic and numerical analyses.
*/
reset(loadprint,pause_prompt)$